﻿@page "/Marging"
@using CarlifeService;
@using Commonality.DTO;
@using ICarlifeService;
@using ICarlifeService.IKeHu;
@using Models;
@inject NavigationManager NavigationManager
@inject IBaoZhengJing services;
@using BootstrapBlazor.Components;

<h3>Marging</h3>

<h3>客户关系管理</h3>
<EditForm Model=@guans>
    <div class="input-group mb-3">
        <div class="input-group-prepend">
            <span class="input-group-text"  id="inputGroup-sizing-default">契约编号：</span>
        </div>
        <InputText @bind-Value=ClientId class="form-control;input-group-prepend" aria-describedby="inputGroup-sizing-default"></InputText>
        <ValidationMessage For="@(() =>ClientId)" />
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">客户名称：</span>
        </div>
        <InputText @bind-Value=ClientName class="form-control;input-group-prepend" aria-describedby="inputGroup-sizing-default"></InputText>
        <ValidationMessage For="@(() =>ClientName)" />
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">   起租日期：</span>
        </div>
        <input @bind="StartTime" type="date" />——
        <input @bind="EndTime" type="date" />
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">   客户类型：</span>
        </div>
        <select @bind="ClientTypeId">
            <option value="0">请选择</option>
            <option value="1">个人客户</option>
            <option value="2">企业客户</option>
        </select>
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">业务经办：</span>
        </div>
        <select @bind="BusinessManagementID">
            <option value="0">请选择</option>
            <option value="10">张三</option>
            <option value="11">李四</option>
            <option value="12">王五</option>
            <option value="21">杨海涛</option>
        </select>
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">保证金状态：</span>
        </div>
        <select @bind="MoneystateID">
            <option value="0">请选择</option>
            <option value="13">待缴纳</option>
            <option value="14">已缴纳</option>
            <option value="15">部分退还</option>
            <option value="16">已退还</option>
            <option value="17">已冲抵</option>
            <option value="18">待审核</option>
        </select>

    </div>
    <button id="search" class="btn btn-outline-secondary" @onclick="show">查询</button>
       <button id="search" class="btn btn-outline-secondary" @onclick="cz">重置</button>

</EditForm>

<div>
    <table class="table-responsive" width="90%">
        <tr>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>契约编号    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>客户名称    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>客户类型    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>还款期次    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>合同保证金    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>已退金额    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>剩余保证金  </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>业务经办    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>保证金状态    </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>起租日期        </h5>     </td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef"><h5>操作        </h5>     </td>
        </tr>

        @foreach (var item in guans)
        {
            <tr>

                <td style="text-align:center;border:1px solid;padding:35px;"><a style="color:blue">@item.ClientId </a> </td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.ClientName</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.TypeName</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.Count</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.ContractBond</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.AmountRefunded</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.RemainingMargin</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.BusinessManagementName</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.MoneystateName</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.RentStartTime</td>

                <td style="border:1px solid">
                    <a href="/AddBook?Id=@item.DepositId">还款记录</a>

                    <a href="/AddBook?Id=@item.DepositId">日志</a>
                </td>
            </tr>

        }

    </table>


</div>



@code {

    [Parameter]
    public DateTime? StartTime { get; set; }
    public DateTime? EndTime { get; set; }
    public string TypeName { get; set; }
    public string ClientName { get; set; }
    public string Phone { get; set; }
    public string ClientId { get; set; }
    public int ClientTypeId { get; set; }
    public int BusinessManagementID { get; set; }
    public int MoneystateID { get; set; }

    private List<DepositDTO> guans;






    protected override async Task OnInitializedAsync()
    {
        guans = services.DepositShow(StartTime, EndTime, ClientId, ClientName, ClientTypeId, BusinessManagementID, MoneystateID);
        await base.OnInitializedAsync();
    }
    public void show()
    {
        guans = services.DepositShow(StartTime, EndTime, ClientId ,  ClientName ,  ClientTypeId , BusinessManagementID , MoneystateID );
    }
    public void tz(string id)
    {
        NavigationManager.NavigateTo($"ClientDetail/{id}");
    }
    public void cz()
    {
        ClientId = "";
        ClientName = "";
        BusinessManagementID = 0;
        ClientTypeId = 0;
        MoneystateID = 0;
        StartTime = null;
        EndTime = null;
        guans = services.DepositShow(StartTime, EndTime, ClientId, ClientName, ClientTypeId, BusinessManagementID, MoneystateID);
    }
}